﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SimpleGameEngine
{
    public class GameState
    {
        public SizeF GameArea;
        public List<GameObject> GameObjects = new List<GameObject>();

        private BaseShip _baseShip;
        private RunningDog _runningdog;

        private GameSpatialManager _spatial_manager;

        public GameState(SizeF gameArea)
        {
            GameArea = gameArea;
        }

        public void Draw(Graphics graphics)
        {
            //Draw the game objects
            foreach (GameObject gameObject in GameObjects)
            {
                gameObject.Draw(graphics);
            }
        }

        public void Update(double elapsedTime)
        {
            _spatial_manager.ClearBuckets();

            //Updates all the game objects
            foreach (GameObject gameObject in GameObjects)
            {
                gameObject.Update(elapsedTime);

                _spatial_manager.RegisterObject(gameObject);
            }
        }

        public void Initialize()
        {
            //Spatial hashing implementation for 2D collition check later
            _spatial_manager = new GameSpatialManager();
            _spatial_manager.initialize((int)GameArea.Width, (int)GameArea.Height, 64);

            //Create all the main gameobjects
            GameObjects.Clear();

            _baseShip = new BaseShip(this, GameArea.Width / 2 - 20, GameArea.Height - 46);
            GameObjects.Add(_baseShip);

            _runningdog = new RunningDog(this, 0, 20);
            GameObjects.Add(_runningdog);
        }
    }
}
